package com.digitalchina.lxnsy.toolkit;

import android.app.Activity;
import android.content.Intent;

import java.io.Serializable;

/**
 * ================================================
 * 项目名称：杨凌农业大数据(数据采集)
 * 类描述：activity跳转工具类
 * 包名：com.digitalchina.bigdata.toolkit
 * 创建人：郑皓
 * 创建时间：2016/4/11 16:59
 * 修改备注：
 * ================================================
 */
public class GotoUtil {

    /**
     * 有参activity跳转
     *
     * @param poFrom
     * @param poTo
     * @param pbFinish
     * @param lsKey
     * @param pmExtra
     */
    public static void gotoActivity(Activity poFrom, Class<?> poTo, boolean pbFinish, String lsKey,
                                    Object pmExtra) {
        Intent loIntent = new Intent(poFrom, poTo);
        if (pmExtra != null)
            loIntent.putExtra(lsKey, (Serializable) pmExtra);
        poFrom.startActivity(loIntent);

        if (pbFinish)
            poFrom.finish();
    }

    /**
     * 有参 不关闭 activity跳转
     *
     * @param poFrom
     * @param poTo
     * @param lsKey
     * @param pmExtra
     */
    public static void gotoActivity(Activity poFrom, Class<?> poTo, String lsKey,
                                    Object pmExtra) {
        Intent loIntent = new Intent(poFrom, poTo);
        if (pmExtra != null)
            loIntent.putExtra(lsKey, (Serializable) pmExtra);
        poFrom.startActivity(loIntent);
    }

    /**
     * 无参activity跳转
     *
     * @param poFrom
     * @param poTo
     * @param pbFinish
     */
    public static void gotoActivity(Activity poFrom, Class<?> poTo, boolean pbFinish) {
        Intent loIntent = new Intent(poFrom, poTo);
        poFrom.startActivity(loIntent);

        if (pbFinish)
            poFrom.finish();
    }

    /**
     * 无参 不关闭 activity跳转
     *
     * @param poFrom
     * @param poTo
     */
    public static void gotoActivity(Activity poFrom, Class<?> poTo) {
        Intent loIntent = new Intent(poFrom, poTo);
        poFrom.startActivity(loIntent);
    }


    /**
     * startActivityForResult 带参数不关闭跳转
     *
     * @param poFrom
     * @param poTo
     * @param requestCode
     * @param lsKey
     * @param pmExtra
     */
    public static void gotoForResultActivity(Activity poFrom, Class<?> poTo, int requestCode, String lsKey, Object pmExtra) {

        Intent loIntent = new Intent(poFrom, poTo);
        if (pmExtra != null) {
            loIntent.putExtra(lsKey, (Serializable) pmExtra);
        }
        poFrom.startActivityForResult(loIntent, requestCode);

    }

    /**
     * startActivityForResult 无参数不关闭跳转
     *
     * @param poFrom
     * @param poTo
     * @param requestCode
     */
    public static void gotoForResultActivity(Activity poFrom, Class<?> poTo, int requestCode) {

        Intent loIntent = new Intent(poFrom, poTo);
        poFrom.startActivityForResult(loIntent, requestCode);

    }

}
